﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GSPatEditor.Bitmaps.DDSImpl
{
    struct Format
    {
        /// <summary>
        /// Image format
        /// </summary>
        public ImageEngineFormat InternalFormat;

        /// <summary>
        /// True = can have mipmaps.
        /// </summary>
        public bool IsMippable
        {
            get
            {
                return InternalFormat.ToString().Contains("DDS");  // KFreon: Of the supported formats, only DDS' are mippable.
            }
        }

        public bool IsBlockCompressed
        {
            get
            {
                return BlockSize >= 8;
            }
        }

        /// <summary>
        /// Size of a compressed block.
        /// Returns -1 if format is not block compressed
        /// </summary>
        public int BlockSize
        {
            get
            {
                return GetBlockSize();
            }
        }

        /// <summary>
        /// Initialises a Format with an image format.
        /// </summary>
        /// <param name="format">Image format</param>
        public Format(ImageEngineFormat format)
        {
            InternalFormat = format;
        }

        private int GetBlockSize()
        {
            int blocksize = 1;
            switch (InternalFormat)
            {
                case ImageEngineFormat.DDS_ATI1:
                case ImageEngineFormat.DDS_DXT1:
                    blocksize = 8;
                    break;
                case ImageEngineFormat.DDS_DXT2:
                case ImageEngineFormat.DDS_DXT3:
                case ImageEngineFormat.DDS_DXT4:
                case ImageEngineFormat.DDS_DXT5:
                case ImageEngineFormat.DDS_ATI2_3Dc:
                    blocksize = 16;
                    break;
                case ImageEngineFormat.DDS_V8U8:
                case ImageEngineFormat.DDS_A8L8:
                    blocksize = 2;
                    break;
                case ImageEngineFormat.DDS_ARGB:
                    blocksize = 4;
                    break;
                case ImageEngineFormat.DDS_RGB:
                    blocksize = 3;
                    break;
            }
            return blocksize;
        }
    }
}
